package logic

import (
	"context"

	"server_1.0/service/question/internal/svc"
	"server_1.0/service/question/question"

	"github.com/zeromicro/go-zero/core/logx"
)

type QueryLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewQueryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryLogic {
	return &QueryLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *QueryLogic) Query(in *question.Empty) (*question.QReps, error) {
	usersHandle := make([]*question.Reps, 0)
	count := 0
	pnos, _ := l.svcCtx.QuestionModel.FindAll(l.ctx)

	for _, item := range pnos {
		usersHandle = append(
			usersHandle,
			&question.Reps{
				No:   item.Qno,
				Info: item.Qinfo,
				OPa:  item.Qopa,
				OPb:  item.Qopb,
				AWa:  item.Qawa,
				AWb:  item.Qawb,
			})
		count += 1
	}
	return &question.QReps{
		Count: int64(count),
		QRs:   usersHandle,
	}, nil
}
